package file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

public class Demo7 {
    public static void main(String[] args) throws IOException {
//        InputStream inputStream = null;
//        try {
//            inputStream = new FileInputStream("./test.txt");
//        }finally {
//            inputStream.close();
//        }

        try(InputStream inputStream = new FileInputStream("./test.txt");) {
            //读文件操作
            while(true) {

                //一次读一个字节
//                int data = inputStream.read();
//                if(data == -1) {
//                    break;
//                }
//                System.out.printf("0x%x\n",data);

                //一次都多个字节
                byte[] data = new byte[1024];
                int n = inputStream.read(data);
                if(n == -1) {
                    break;
                }
                for (int i = 0; i < n; i++) {
                    System.out.printf("0x%x\n", data[i]);
                }
            }
        }

    }
}
